<?php

namespace Modules\Shop\Http\Controllers;

use HiCommon\Service\CheckpointService;
use Illuminate\Support\Facades\Request;

class CheckpointController extends BaseController
{

    /**
     * 检测机构列表
     */
    public function index()
    {
        $data = Request::input();
        $list = CheckpointService::checkpointList($data);

        return view('shop::checkpoint.index', ['list' => $list, 'data' => $data]);
    }

    /**
     * 删除
     */
    public function del()
    {
        $data = Request::all('id');
        return CheckpointService::del($data);
    }



    /*******************************************检测机构开放日期*************************************************/

    /**
     * 检测机构开放日期列表
     */
    public function dayLists()
    {
        try {
            $data['start'] = date('Y-m-d', time());
            return view('shop::checkpoint.dayLists',['data'=>$data]);
        }
        catch (\Exception $exception) {
            return hello_error('失败-'.$exception->getMessage(),[],$exception->getMessage());
        }

    }

    /**
     * 检测机构开放日期列表
     */
    public function getDayLists()
    {
        $search = Request::input();
        $search['start'] = $search['start'] ?? date('Y-m-d', time());
        $n_shop_id = intval(shop_shop_id());
        $list = CheckpointService::dayLists($n_shop_id,$search);

        $data = [
            'code'  => 0,
            'msg'   => '正在请求中...',
            'count' => $list['total'],
            'data'  => $list['data'],
        ];

        return response()->json($data);
    }

    /**
     * 添加
     */
    public function create()
    {
        $n_shop_id = intval(shop_shop_id());
        $data = CheckpointService::checkDay($n_shop_id);
        return view('shop::checkpoint.create', $data);
    }

    /**
     * 添加
     */
    public function store()
    {
        $data = Request::all();
        $n_shop_id = intval(shop_shop_id());
        return CheckpointService::addDay($n_shop_id,$data);
    }

    /**
     *删除开放日期
     */
    public function delDate($id)
    {
        return CheckpointService::delDate($id);
    }

    /**
     * 编辑列表
     */
    public function update()
    {
        $data = Request::all();

        return CheckpointService::updateDay($data);
    }
}
